package com.woniu.his.bms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.bms.client.SettlementCatClient;
import com.woniu.his.bms.client.param.FindSettlementCatParam;
import com.woniu.his.bms.client.param.UpdateSettlementCatParam;
import com.woniu.his.bms.client.result.PageSettlementCatResult;
import com.woniu.his.bms.client.result.SettlementCatResult;
import com.woniu.his.bms.service.dto.PageSettlementCatDto;
import com.woniu.his.bms.service.dto.SettlementCatDto;
import com.woniu.his.bms.service.param.FindSettlementCatServiceParam;
import com.woniu.his.bms.service.param.UpdateSettlementCatServiceParam;
import com.woniu.his.result.Result;
import com.woniu.his.bms.service.SettlementCatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/bms")
public class SettlementCatApiImpl implements SettlementCatClient {

    @Resource
    private SettlementCatService settlementCatService;

    @Override
    public Result addSettlementCat(String name) {

        log.info("新增结算类别传回来的参数：{}",name);
        settlementCatService.addSettlementCat(name);
        return Result.getInstance();
    }

    @Override
    public Result deleteSettlementCat(List<Long> ids) {

        log.info("删除结算类别传回来的参数：{}",ids);
        settlementCatService.deleteSettlementCat(ids);
        return Result.getInstance();
    }

    @Override
    public Result<PageSettlementCatResult> findSettlementCatByCondition(FindSettlementCatParam param) {

        log.info("查寻结算类别条件传的参数：{}", param);
        FindSettlementCatServiceParam serviceParam = BeanUtil.copyProperties(param, FindSettlementCatServiceParam.class);
        PageSettlementCatDto list = settlementCatService.findDept(serviceParam);
        PageSettlementCatResult result = BeanUtil.copyProperties(list, PageSettlementCatResult.class);
        return Result.getInstance(PageSettlementCatResult.class).setData(result);
    }

    @Override
    public Result<List<SettlementCatResult>> queryAllSettlementCat() {

        log.info("查询所有结算类别");
        List<SettlementCatDto> list=settlementCatService.queryAllSettlementCat();
        List<SettlementCatResult> result = BeanUtil.copyToList(list,SettlementCatResult.class);
        return Result.getInstanceList(SettlementCatResult.class).setData(result);
    }

    @Override
    public Result updateSettlementCatByCondition(@Valid UpdateSettlementCatParam param) {

        log.info("更新结算类别传的参数:{}",param);
        UpdateSettlementCatServiceParam serviceParam=BeanUtil.copyProperties(param, UpdateSettlementCatServiceParam.class);
        settlementCatService.updateSettlementCat(serviceParam);
        return Result.getInstance();
    }
}
